﻿using System.ServiceProcess;
using EP.Base.BaseService.Manager.Container;
using EP.Base.BaseService.Manager.Interface.Common;

namespace EP.Base.BaseService.Manager.Service.Es
{
    public partial class EsManagerService : ServiceBase
    {
        private IServiceMonitor _serviceMonitor;
        private readonly IServiceSimplifyLog _serviceSimplifyLog;
        public EsManagerService()
        {
            _serviceSimplifyLog = AppContainer.Resolve<IServiceSimplifyLog>();
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            _serviceSimplifyLog.ExecSl("服务启动", () =>
            {
                _serviceMonitor = AppContainer.Resolve<IServiceMonitor>();
                _serviceMonitor.Register(AppContainer.Resolve<IAutoMonitorService>(Config.EsMaintainTaskConfig.TaskAutoMonitorService));
                _serviceMonitor.Start();
            });
            
            
        }

        protected override void OnStop()
        {
            _serviceSimplifyLog.ExecSl("服务停止", () =>
            {
                if (_serviceMonitor != null)
                    _serviceMonitor.Stop();
            });
        }
    }
}
